<template>
  <div>
    <div class="system-user-search mb15">
				<el-input size="default" placeholder="请输入科室名称" v-model="dpcname" style="max-width: 180px"> </el-input>
				<el-button size="default" type="primary" @click="dpcselect(pagess,sizess,dpcname)" class="ml10">
					<el-icon>
						<ele-Search />
					</el-icon>
					查询
				</el-button>
				<el-button size="default" type="success" class="ml10" @click="dialogFormVisible = true">新增科室</el-button>

<el-dialog title="科室添加" :visible.sync="dialogFormVisible">
  <el-form :model="form">
    <el-form-item label="科室名称" :label-width="formLabelWidth">
      <el-input v-model="form.dpc_name" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="所属部门" :label-width="formLabelWidth">
      <el-select v-model="form.cdp_id" placeholder="请选择所属部门">
        <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.dpName" 
      :value="item.dpId">
    </el-option>
      </el-select>
    </el-form-item>
    
    <el-form-item label="科室描述" :label-width="formLabelWidth">
      <el-input type="textarea" v-model="form.dpc_description"  :rows="2" placeholder="请输入内容" :v-model="textarea"></el-input>
    </el-form-item>
    <el-form-item label="是否是治疗科室" :label-width="formLabelWidth">
      <el-input v-model="form.dpc_iscure" autocomplete="off"></el-input>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="dialogFormVisible = false">取 消 添 加</el-button>
    <el-button type="primary" @click="add(form.dpc_name,form.cdp_id,form.dpc_description,form.dpc_iscure)">确 定 添 加</el-button>
  </div>
</el-dialog>&nbsp;
			</div>
      
      <el-table
    :data="pagination.records"
    border 
    style="width: 100%;height:530px">
    <el-table-column  fixed prop="dpcId"  label="科室ID"   width="80"></el-table-column>
    <el-table-column fixed prop="dpcName" label="科室名称"    width="80"> </el-table-column>
    <el-table-column  prop="dpId" label="所属部门ID"    width="100" :formatter="stateFormat"> </el-table-column>
    <el-table-column   prop="dpcDescription" label="科室描述"   width="900"> </el-table-column>
    <el-table-column  prop="dpcIscure"  label="是否是治疗科室"   width="130">
     <el-switch
  v-model="value"
  active-color="#13ce66"
  inactive-color="#ff4949">
</el-switch>
  </el-table-column>
  </el-table>
  <div class="block">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :hide-on-single-page="true"
      :current-page="pagination.current"
		  :page-sizes="[4]"
		  :page-size="pagination.size"
		  layout="total,sizes, prev, pager, next, jumper"
		  :total="pagination.total">
    </el-pagination>
  </div>
    <!-- <el-button @click="list()"  >测速</el-button> -->
  </div>
</template>

<script>
import dept from '@/api/dept1'

export default {
  name: 'deptList',
  methods:{
    
    //分页
        handleSizeChange(value) {
          this.pagination.size = value
          this.list(this.pagination.current,this.pagination.size);
       },
        handleCurrentChange(value) {
          this.pagination.current = value
          this.list(this.pagination.current,this.pagination.size);
       },
       list(pages,sizes){
          dept.selectoutdep(pages,sizes).then(resp=>{
          this.pagination=resp;
          console.log(this.pagination)
        });
        dept.selectdepart().then(resp=>{
          this.options=resp
          console.log(this.options)
        });
       },
      //  选择器点击查询
       selectdp(dpId){
         dept.selectdpcdep(dpId).then(resp=>{
          this.pagination=resp;
          console.log(this.pagination)
         });
       },
       dpcselect(pagess,sizess,dpcname){
         dept.selectdpc(pagess,sizess,dpcname).then(resp=>{
           this.pagination=resp;
           console.log(this.pagination)
         }
         );},
       add(dpc_name,cdp_id,dpc_description,dpc_iscure){
           dept.adddpc(dpc_name,cdp_id,dpc_description,dpc_iscure).then(resp=>{
             alert("添加成功");
         });
         }
         
        
  },
  data() {
      return {
        pagination:{},
        textarea: '',
        dpcname:"",
        pagess:1,
        sizess:4,
        options: [{
          value:'',
          label:''
        }],
        formLabelWidth: '120px',
        dialogFormVisible: false,
        form: {
          dpc_name: '',
          cdp_id: '',
          dpc_description:'',
          dpc_iscure:'',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        stateFormat(row, column) {
          if (row.dpId === 1) {
            return '门诊部'
            }
            if(row.dpId === 2){
              return '住院部'
              } 
              if(row.dpId === 3){
              return '药房部'
              } 
              if(row.dpId === 4){
              return '财务部'
              } 
              },
        value:true
      }
    },  
    mounted() {
        this.list(1,4);
    },
  };
  
      
</script>
